package com.softserveinc.autorent.model;

import java.io.Serializable;
import javax.persistence.*;

import java.util.List;


/**
 * The persistent class for the car_model database table.
 * 
 */
@Entity
@Table(name="car_model")
@NamedQueries({
@NamedQuery(name = "CarModel.findAll", query = "SELECT m FROM CarModel m"),
@NamedQuery(name = "CarModel.findById", query = "SELECT m FROM CarModel m WHERE m.id = :id"),
@NamedQuery(name = "CarModel.findAllByCarVendorId", query = "SELECT m FROM CarModel m WHERE m.carVendor.id = :id")
})
public class CarModel implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7503605373397170291L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(unique=true, nullable=false)
	private int id;

	@Column(name="drive_category", length=2)
	@Enumerated(EnumType.STRING)
	private  CarDriveCategoryEnum driveCategory;

	@Column(nullable=false, length=50)
	private String name;

	//bi-directional many-to-one association to Car
	@OneToMany(mappedBy="carModel")
	private List<Car> cars;

	//bi-directional many-to-one association to Vendor
	@ManyToOne
	@JoinColumn(name="car_vendor_id", nullable=false)
	private CarVendor carVendor;

	//bi-directional many-to-one association to CarPhoto
	@OneToMany(mappedBy="carModel")
	private List<CarPhoto> carPhotos;

	public CarModel() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public CarDriveCategoryEnum getDriveCategory() {
		return this.driveCategory;
	}

	public void setDriveCategory(CarDriveCategoryEnum driveCategory) {
		this.driveCategory = driveCategory;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Car> getCars() {
		return this.cars;
	}

	public void setCars(List<Car> cars) {
		this.cars = cars;
	}

	public CarVendor getCarVendor() {
		return this.carVendor;
	}

	public void setCarVendor(CarVendor carVendor) {
		this.carVendor = carVendor;
	}

	public List<CarPhoto> getCarPhotos() {
		return this.carPhotos;
	}

	public void setCarPhotos(List<CarPhoto> carPhotos) {
		this.carPhotos = carPhotos;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((carPhotos == null) ? 0 : carPhotos.hashCode());
		result = prime * result
				+ ((carVendor == null) ? 0 : carVendor.hashCode());
		result = prime * result + ((cars == null) ? 0 : cars.hashCode());
		result = prime * result
				+ ((driveCategory == null) ? 0 : driveCategory.hashCode());
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CarModel other = (CarModel) obj;
		if (carPhotos == null) {
			if (other.carPhotos != null)
				return false;
		} else if (!carPhotos.equals(other.carPhotos))
			return false;
		if (carVendor == null) {
			if (other.carVendor != null)
				return false;
		} else if (!carVendor.equals(other.carVendor))
			return false;
		if (cars == null) {
			if (other.cars != null)
				return false;
		} else if (!cars.equals(other.cars))
			return false;
		if (driveCategory != other.driveCategory)
			return false;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	

}